package com.example.yls.demoa;

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
    private Button button;
    private HighPriorityReceiver highPriorityReceiver;
    private MiddlePriorityReceiver middlePriorityReceiver;
    private LowPriorityReceiver lowPriorityReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        highPriorityReceiver = new HighPriorityReceiver();
        IntentFilter highFilter = new IntentFilter();
        highFilter.addAction("ORDERED_BROADCAST");
        highFilter.setPriority(100);
        registerReceiver(highPriorityReceiver,highFilter);

        middlePriorityReceiver = new MiddlePriorityReceiver();
        IntentFilter midFilter = new IntentFilter();
        midFilter.addAction("ORDERED_BROADCAST");
        midFilter.setPriority(50);
        registerReceiver(middlePriorityReceiver,midFilter);

        lowPriorityReceiver = new LowPriorityReceiver();
        IntentFilter lowFilter = new IntentFilter();
        lowFilter.addAction("ORDERED_BROADCAST");
        lowFilter.setPriority(0);
        registerReceiver(lowPriorityReceiver,lowFilter);


        findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setAction("ORDERED_BROADCAST");
                sendOrderedBroadcast(intent,null);
            }
        });
    }
}
